﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ChineseChess.Game.Rules
{
    class JuRule : Rule
    {
        private List<Piece> pies = null;
        public override bool IsDown { get; set; }
        public override List<Point> getNextPos(Piece pie, List<Piece> pies)
        {
            this.pies = pies;
            List<Point> pList = new List<Point>();
            int x = 0;
            int y = 0;
            for (x = pie.X - 1; x >= 0; x--)
            {
                y = pie.Y;
                if (!this.Add(pie, pList, x, y))
                {
                    break;
                }
            }
            for (x = pie.X + 1; x <= 8; x++)
            {
                y = pie.Y;
                if (!this.Add(pie, pList, x, y))
                {
                    break;
                }
            }
            for (y = pie.Y + 1; y <= 9; y++)
            {
                x = pie.X;
                if (!this.Add(pie, pList, x, y))
                {
                    break;
                }
            }
            for (y = pie.Y - 1; y >= 0; y--)
            {
                x = pie.X;
                if (!this.Add(pie, pList, x, y))
                {
                    break;
                }
            }
            return pList;
        }

        private bool Add(Piece pie, List<Point> pList, int x, int y)
        {
            Piece p = Chessboard.getPieByXy(x, y, pies);
            if (p != null)//判断要走的坐标是否有自己一方的棋
            {
                if (p.isRed != pie.isRed)
                {
                    pList.Add(new Point(x, y));
                }
                return false;
            }
            pList.Add(new Point(x, y));
            return true;
        }
    }
}
